using ACM.cmsarea08.DBManager;
using ACM.cmsarea08.mainconfiguration;
using System;
using System.Web;

namespace ACM.cmsarea08.Administration.Core {
	public struct DBHelper  {

		
		public string getAdminMenuItems() {
			return "select id,titolo,descrizione,lingua from " +ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "menu_tipolink where lingua=?lingua order by id asc ;";
		}		
		/*
		public string GetAdminMenu() {
			return "select * from " +ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "admin_menu where enabled='1' and (lingua=?lingua or lingua='') order by figliodi,ordine ;";
		}
		public string GetAdminMenu(string roles) {
			string s = "select * from " +ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "admin_menu where enabled='1' and (lingua=?lingua or lingua='') and ("+roles+") order by figliodi,ordine ;";
			//HttpContext.Current.Response.Write("QQ:<hr/>" + s + "<br/>");
			
			return s;
		}		
		
		public string GetCustomAdminMenu(string ruolo,string lingua, string TablePrefix) {
			string baseQuery="select * " +
                            "" +
                            " from "+TablePrefix +"user_menu " +
                            " where relatedto='"+ruolo+"' and position='top' and role='group' and (lang='"+lingua+"' or lang='') order by sonof  ";
			return baseQuery;
		}			
		*/
		public string GetAdminSezioni(string filter) {
//			HttpContext.Current.Response.Write(string.Format("select id,titolo from " +ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "contenuti_manager where lingua=?lingua and tipo=?ctype {0} order by titolo ;",filter));
			return string.Format("select id,titolo from " +ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "contenuti_manager where lingua=?lingua and tipo=?ctype  {0} order by titolo ;",filter);
		}
		
		public string GetDropAdminLanguage() {
			//HttpContext.Current.Response.Write("select * from " +itareanet.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "contenuti_manager where lingua=?lingua and tipo=?ctype order by titolo ;");
			return "select cultureinfo,nome_lingua from " +ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "lingue where enabled='1' order by predef desc, nome_lingua asc ;";
		}		
		public string GetListMenu(string lingua) {
			//HttpContext.Current.Response.Write("select id, titolo, a_titolo, isFiglio, PadreID, lingua_ref,menu_contenitore, ordine from " +ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "menu_elemento where lingua_ref='" + lingua + "' order by ordine, PadreID asc  ;<hr>");
			return "select id, titolo, a_titolo, isFiglio, PadreID, lingua_ref,menu_contenitore, ordine from " +ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "menu_elemento where lingua_ref='" + lingua + "' order by ordine, PadreID asc  ;";
		}
		public string GetListMenu() {
			//HttpContext.Current.Response.Write("select id, titolo, a_titolo, isFiglio, PadreID, lingua_ref,menu_contenitore, ordine from " +ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "menu_elemento where lingua_ref='" + lingua + "' order by ordine, PadreID asc  ;<hr>");
			return "select id, titolo, a_titolo, isFiglio, PadreID, lingua_ref,menu_contenitore, ordine from " +ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "menu_elemento order by lingua_ref, ordine, PadreID asc  ;";
		}
		public string GetMenuNames() {
//			HttpContext.Current.Response.Write("select id, titolo, ordine,(select ismenu from " + ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle + "componenti " +
//				"where id=id_componente) as isMenu from " +ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "moduli having isMenu='1' " +
//				"order by ordine asc  ;");
			return "select id, titolo, ordine,(select ismenu from " + ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle + "componenti " +
				"where id=id_componente) as isMenu from " +ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "moduli having isMenu='1' " +
				"order by ordine asc  ;";
		}
		public string GetRoles(bool allRoles) {
//			HttpContext.Current.Response.Write("select * from " +ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "ruoli ;");
			return "select * from " +ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "ruoli " +
				(!allRoles?"where punti >="+ACM.cmsarea08.Users.CurrentUser.Role.Score.ToString():"") +
				 ";";
		}
		public string GetDropAdminComponents() {
			//HttpContext.Current.Response.Write("select * from " +itareanet.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "contenuti_manager where lingua=?lingua and tipo=?ctype order by titolo ;");
			return "select id,titolo from " +
				" " +ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "componenti as components " +
				" where if(clonabile='0',(select if(count(*)>0,false,true) from " +ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "moduli where id_componente = components.id),true) " +
				" {0} order by titolo ;";
		}		
		public string GetDropAdminComponentsInstance() {
			//HttpContext.Current.Response.Write("select * from " +itareanet.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "contenuti_manager where lingua=?lingua and tipo=?ctype order by titolo ;");
			return "select id,titolo from " +ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "moduli order by titolo ;";
		}		
		public string GetDropAdminComponentsInstance(string filtercomponentname) {
			return "select id,titolo from " +ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "moduli " +
				"where id_componente= (select id from " +ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "componenti where titolo='"+filtercomponentname+"' limit 1) order by titolo ;";
		}		

		
		public string GetDropAdminBlocchiVisivi() {
			//HttpContext.Current.Response.Write("select * from " +itareanet.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "contenuti_manager where lingua=?lingua and tipo=?ctype order by titolo ;");
			return "select id,titolo from " +ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "blocco_visivo where enabled='1' order by titolo ;";
		}		
		public string GetAdminCategorieSEL() {
			//HttpContext.Current.Response.Write("select * from " +itareanet.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "contenuti_manager where lingua=?lingua and tipo=?ctype order by titolo ;");
			return "select id,titolo from " +ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "contenuti_manager where lingua=?lingua and tipo=?ctype and figliodi=?selson order by titolo ;";
		}
		public string getAdminArticleSelected() {
			//HttpContext.Current.Response.Write("select * from " +itareanet.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "contenuti_manager where lingua=?lingua and tipo=?ctype order by titolo ;");
			return "select id,titolo from " +ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "contenuti where sez_id=?selson and cat_id=?catson order by titolo ;";
		}		
		public string GetAdminModuliInst() {
			//HttpContext.Current.Response.Write("select * from " +itareanet.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "contenuti_manager where lingua=?lingua and tipo=?ctype order by titolo ;");
			return "SELECT `id`,titolo,descrizione, visible_home, lockid,ordine, enabled,`protected`, " +
				"(select titolo from "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"componenti where id = "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"moduli.id_componente) as componente, " +
				"(select readonlysf from "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"componenti where id = "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"moduli.id_componente) as readonlysf, " +
				"(select titolo from "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"blocco_visivo where id = "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"moduli.blocco_visivo) as bloccovisivo, " +
				"data_mod," +
				"(select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"moduli ) as uconteggio " +
				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"moduli " +
				"order by protected desc, blocco_visivo asc, ordine asc limit ?startl, ?offsetl";
		}
		public string GetAdminComponentInst() {
			//HttpContext.Current.Response.Write("select * from " +itareanet.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "contenuti_manager where lingua=?lingua and tipo=?ctype order by titolo ;");
			return "SELECT * " +
				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"componenti " +
				"order by data_ins desc limit ?startl, ?offsetl";
		}		
		public string GetAdminSezioniList() {
		/*	HttpContext.Current.Response.Write("SELECT `id`,titolo,descrizione, ordine, figliodi, lingua, " +
				"(select count(*) from "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager where figliodi = "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager.id) as countcat, " +
				"data_mod," +
				"(select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager ) as uconteggio " +
				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager " +
				"where tipo='c' order by ordine asc limit ?startl, ?offsetl");*/
			return "SELECT contents.`id`,contents.`id` as idf, contents.titolo,contents.lockid,contents.descrizione, contents.ordine, " +
				"(select nome_lingua from " +
				ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle + "lingue where cultureinfo=contents.lingua) as lingua, " +
				"(select count(*) from "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+
				"contenuti_manager where managed='-1' and figliodi = idf) as countcat, " +
				"contents.data_mod," +
				"(select titolo from "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+
								   "contenuti_manager where id=contents.tradotto_da) as tradotto_daNOME,"+
				"(select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+
				"contenuti_manager where managed='-1' and tipo='S' ) as uconteggio, " +
				"'0' as isrev, contents.tradotto_da " +
				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager as contents " +
				"inner join "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenutiruoli as ruoli " +
				"on ( INSTR('" + string.Join("~",ACM.cmsarea08.Users.CurrentUser.Ruoli) + "',ruoli.ruolo)>0 and ruoli.id=contents.id and contents.tipo=ruoli.tipo ) " +
				"where managed='-1' and contents.tipo='S'  ;";
		}
		public string GetAdminCategorieList() {
		/*	HttpContext.Current.Response.Write("SELECT `id`,`id` as idf, titolo,descrizione, ordine, figliodi, lingua, " +
				"(select titolo from "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager where "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager.id as idf = figliodi) as padre, " +
				"data_mod," +
				"(select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager ) as uconteggio " +
				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager " +
				"where tipo='C' order by ordine asc limit ?startl, ?offsetl");*/
			return "SELECT `id`, titolo,lockid,descrizione, ordine, figliodi as figliodiID,(select nome_lingua from " + 
				ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle + "lingue where cultureinfo=contents.lingua) as lingua, " +
				"(select titolo from "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager where "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager.id = figliodiID and tipo='S') as figliodiNOME, " +
				"data_mod," +
				"(select titolo from "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+
								   "contenuti_manager where id=contents.tradotto_da) as tradotto_daNOME,"+
				"(select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager where managed='-1' and tipo='C') as uconteggio, " +
				"'0' as isrev, tradotto_da " +
				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager as contents " +
				"where managed='-1' and tipo='C' order by ordine asc limit ?startl, ?offsetl";
		}
		public string GetAdminCategoria() {
			/*HttpContext.Current.Response.Write("SELECT `id`, titolo,descrizione, ordine, figliodi as figliodiID, lingua, " +
				"(select titolo from "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager where "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager.id = figliodiID and tipo='S') as figliodiNOME, " +
				"data_mod," +
				"(select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager ) as uconteggio " +
				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager " +
				"where tipo='C' and figliodi=?id order by ordine asc limit ?startl, ?offsetl");*/
			return "SELECT `id`, titolo,lockid,descrizione, ordine, figliodi as figliodiID, (select nome_lingua from " + 
				ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle + "lingue where cultureinfo=contents.lingua) as lingua, " +
				"(select titolo from "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager where "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager.id = figliodiID and tipo='S') as figliodiNOME, " +
				"data_mod," +
				"(select titolo from "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+
								   "contenuti_manager where id=contents.tradotto_da) as tradotto_daNOME,"+
				"(select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager where managed='-1' and tipo='C' " +
				"and figliodi=?id ) as uconteggio, " +
				"'0' as isrev, tradotto_da " + 
				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager as contents " +
				"where managed='-1' and tipo='C' and figliodi=?id order by ordine asc limit ?startl, ?offsetl";
		}
		public string GetAdminCategorieListRev() {
		
			return "(SELECT cast(contents.`id` as char) as id, titolo,lockid,descrizione, ordine, figliodi as figliodiID,(select nome_lingua from " + 
				ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle + "lingue where cultureinfo=contents.lingua) as lingua, " +
				"(select titolo from "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager where id = figliodiID and tipo='S') as figliodiNOME, " +
				"data_mod," +
				"(select titolo from "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+
								   "contenuti_manager where id=contents.tradotto_da) as tradotto_daNOME,"+
				"((select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager where managed='-1' and tipo='C') + " +
				"(select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"rev_contenuti_manager where managed='-1' and tipo='C')) as uconteggio, '0' as isrev, tradotto_da " +
				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager as contents " +
				"where managed='-1' and tipo='C' "+
				") union " +
				"(SELECT cast(concat('rev',contents.`id`) as char) as id , titolo,lockid,descrizione, ordine, figliodi as figliodiID, " +
				"(select nome_lingua from " + ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle + "lingue where cultureinfo=contents.lingua) " +
				"as lingua, " +
				"(select titolo from "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"rev_contenuti_manager where id = contents.figliodi and tipo='S') as figliodiNOME, " +
				"data_mod," +
				"'' as tradotto_daNOME,"+
				"((select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager where managed='-1' and tipo='C') + " +
				"(select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"rev_contenuti_manager where managed='-1' and tipo='C' )) as uconteggio, '1' as isrev, '-1' as tradotto_da " +
				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"rev_contenuti_manager as contents " +
				"where managed='-1' and tipo='C' ) order by ordine asc limit ?startl, ?offsetl";
		}
		public string GetAdminCategoriaRev() {
		
			return "(SELECT cast(contents.`id` as char) as id, titolo,lockid,descrizione, ordine, figliodi as figliodiID, (select nome_lingua from " + 
				ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle + "lingue where cultureinfo=contents.lingua) as lingua, " +
				"(select titolo from "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager where id = figliodiID and tipo='S') as figliodiNOME, " +
				"data_mod," +
				"((select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager where tipo='C') + " +
				"(select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"rev_contenuti_manager where tipo='C' )) as uconteggio, '0' as isrev, tradotto_da " +
				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager as contents " +
				"where managed='-1' and tipo='C' and figliodi=?id "+
				") union " +
				"(SELECT cast(concat('rev',contents.`id`) as char) as id , titolo,lockid,descrizione, ordine, figliodi as figliodiID, (select nome_lingua from " + 
				ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle + "lingue where cultureinfo=contents.lingua) as lingua, " +
				"(select titolo from "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager where id = contents.figliodiID and tipo='S') as figliodiNOME, " +
				"data_mod," +
				"((select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager where managed='-1' and tipo='C') + " +
				"(select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"rev_contenuti_manager where managed='-1' and tipo='C' )) as uconteggio, '1' as isrev, '-1' as tradotto_da " +
				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"rev_contenuti_manager as contents " +
				"where managed='-1' and tipo='C' and figliodi=?id ) order by ordine asc limit ?startl, ?offsetl";
		}
		public string GetAdminBlocchiVisivi() {
			//HttpContext.Current.Response.Write("select * from " +itareanet.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "contenuti_manager where lingua=?lingua and tipo=?ctype order by titolo ;");
			return "SELECT `id` ,titolo,lockid,ordine, enabled, " +
				"(select username from "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"utenti where id = bvies.lockid) as lockedby, " +
				"data_mod," +
				"cast( (select group_concat( concat('<a href=''/administration/core/edit_modulo.aspx?IDM=',id,'&SNM=',titolo,'''>',titolo,'</a>') SEPARATOR '<br/>') from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"moduli where blocco_visivo = bvies.`id` order by ordine asc ) as char) as sons, " +
				"(select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"blocco_visivo ) as uconteggio " +
				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"blocco_visivo as bvies " +
				"order by ordine asc limit ?startl, ?offsetl";
		}
		public string GetAdminBloccoVisivo(string id) {
//			HttpContext.Current.Response.Write("SELECT `id` ,titolo FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"blocco_visivo where id='" + id + "' limit 1 ;");
			return "SELECT `id` ,titolo FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"blocco_visivo " +
				"where id='" + id + "' limit 1 ;";
		}
		public string GetAdminTemplate() {
			//HttpContext.Current.Response.Write("select * from " +itareanet.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "contenuti_manager where lingua=?lingua and tipo=?ctype order by titolo ;");
			return "SELECT `id` ,titolo, predef, " +
				"data_mod," +
				"(select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"template ) as uconteggio " +
				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"template " +
				"order by data_ins desc limit ?startl, ?offsetl";
		}
		public string GetAdminTimezone() {
			//HttpContext.Current.Response.Write("select * from " +itareanet.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "contenuti_manager where lingua=?lingua and tipo=?ctype order by titolo ;");
			return "SELECT `time_id` ,concat(short_desc,', ', full_desc) as meta_desc " +
				"" +
				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"timezones " +
				"order by time_id asc";
		}		
		//marco GetAdminLingue
		public string GetAdminLingue() {
			//HttpContext.Current.Response.Write("select * from " +itareanet.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "contenuti_manager where lingua=?lingua and tipo=?ctype order by titolo ;");
			return "SELECT `nome_lingua` ,predef,cultureinfo, data_mod,enabled, " +
//				"data_mod," +
				"(select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"lingue ) as uconteggio " +
				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"lingue " +
			//	"where enabled='1'" +
				"order by ordine asc limit ?startl, ?offsetl";
		}
		//marco GetAdminContenuti ATTENZIONE DA COMPLETARE SELEZIONO SOLO QUESTI CAMPI PER PROVA 
		/*
		public string GetAdminContenuti() {
//			HttpContext.Current.Response.Write("SELECT contents.`id` ,contents.titolo, contents.enabled,contents.managed, (select nome_lingua from " + 
//				ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle + "lingue where cultureinfo=lingua) as lingua, " +
//				"contents.data_mod,contents.ordine," +
//				"(select titolo from "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+
//								   "contenuti where id=contents.tradotto_da) as tradotto_daNOME,"+
//				"sections.titolo as sec_title, categories.titolo as cat_title, sez_id, cat_id," + 
//				"(select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti as contcont where contcont.managed='-1'  ) as uconteggio, " +
//				"'0' as isrev " + 
//				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti as contents " +
//				"left join "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager as sections on contents.sez_id=sections.id " +
//				"left join "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager as categories on contents.cat_id=categories.id where contents.managed='-1'  " +				
//				"order by data_mod desc limit ?startl, ?offsetl");
//			
			return "SELECT contents.`id` ,contents.titolo,contents.lockid, contents.enabled,contents.managed, (select nome_lingua from " + 
				ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle + "lingue where cultureinfo=contents.lingua) as lingua, " +
				"contents.data_mod,contents.ordine," +
				"(select titolo from "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+
								   "contenuti where id=contents.tradotto_da) as tradotto_daNOME,"+
				"sections.titolo as sec_title, categories.titolo as cat_title, sez_id, cat_id," + 
				"(select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti as contcont where contcont.managed='-1' ) as uconteggio, " +
				"'0' as isrev " + 
				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti as contents " +
				"left join "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager as sections on contents.sez_id=sections.id " +
				"left join "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager as categories on contents.cat_id=categories.id where contents.managed='-1'  " +				
				"order by data_mod desc limit ?startl, ?offsetl";
		}
		public string GetAdminContenuti_filtered() {
			//HttpContext.Current.Response.Write("select * from " +itareanet.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "contenuti_manager where lingua=?lingua and tipo=?ctype order by titolo ;");
			return "SELECT contents.`id` ,contents.titolo,contents.lockid, contents.enabled,contents.managed,  (select nome_lingua from " + 
				ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle + "lingue where cultureinfo=contents.lingua) as lingua, " +
				"contents.data_mod,contents.ordine," +
				"(select titolo from "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+
								   "contenuti where id=contents.tradotto_da) as tradotto_daNOME,"+
				"sections.titolo as sec_title, categories.titolo as cat_title, sez_id, cat_id," + 
				"(select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti where managed='-1'  " +
				"and if(?filter1<>'',sez_id=?filter1,true) and if(?filter2<>'',cat_id=?filter2,true) ) as uconteggio, " +
				"'0' as isrev " +
				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti as contents " +
				"left join "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager as sections on contents.sez_id=sections.id " +
				"left join "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager as categories on contents.cat_id=categories.id " +
				"where contents.managed='-1' and if(?filter1<>'',sez_id=?filter1,true) and if(?filter2<>'',cat_id=?filter2,true)" +
				"order by data_mod desc limit ?startl, ?offsetl";
		}
		*/
		
		public string GetAdminContenutiRev() {
			string query = "(SELECT cast(contents.`id` as char) as id ,contents.titolo,contents.lockid, contents.enabled,contents.managed, (select nome_lingua from " + 
				ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle + "lingue where cultureinfo=contents.lingua) as lingua, " +
				"contents.data_mod,contents.ordine," +
				"(select titolo from "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+
								   "contenuti where id=contents.tradotto_da) as tradotto_daNOME,"+
				"sections.titolo as sec_title, categories.titolo as cat_title, sez_id, cat_id," + 
				"((select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti as concont where concont.managed='-1') + " +
				"(select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"rev_contenuti as revcont where revcont.managed='-1' )) as uconteggio, '0' as isrev  " +
				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti as contents " +
				"left join "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager as sections on contents.sez_id=sections.id " +
				"left join "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager as categories on contents.cat_id=categories.id where contents.managed='-1' )" +
				"union " +
				"(SELECT cast(concat('rev',contents.`id`) as char) as id ,contents.titolo,contents.lockid, contents.enabled,contents.managed, (select nome_lingua from " + 
				ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle + "lingue where cultureinfo=contents.lingua) as lingua, " +
				"contents.data_mod,contents.ordine," +
				"'' as tradotto_daNOME,"+
				"sections.titolo as sec_title, categories.titolo as cat_title, sez_id, cat_id, " + 
				"((select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti as concont where concont.managed='-1' ) + " +
				"(select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"rev_contenuti as revcont where revcont.managed='-1' )) as uconteggio, '1' as isrev " +
				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"rev_contenuti as contents " + 
				"left join "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager as sections on contents.sez_id=sections.id " +
				"left join "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager as categories on contents.cat_id=categories.id where contents.managed='-1' )" +				
				"order by data_mod,sez_id,cat_id,titolo desc limit ?startl, ?offsetl";
			return query;
		}
		public string GetAdminContenutiRev_filtered() {
			
			string query = "(SELECT cast(contents.`id` as char) as id,contents.titolo,contents.lockid, contents.enabled,contents.managed, (select nome_lingua from " + 
				ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle + "lingue where cultureinfo=contents.lingua) as lingua, " +
				"contents.data_mod,contents.ordine," +
				"(select titolo from "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+
								   "contenuti where id=contents.tradotto_da) as tradotto_daNOME,"+
				"sections.titolo as sec_title, categories.titolo as cat_title, sez_id, cat_id," + 
				"((select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti) + " +
				"(select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"rev_contenuti ) " +
				"where if(?filter1<>'',sez_id=?filter1,true) and if(?filter2<>'',cat_id=?filter2,true) ) as uconteggio, '0' as isrev  " +
				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti as contents " +
				"left join "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager as sections on contents.sez_id=sections.id " +
				"left join "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager as categories on contents.cat_id=categories.id where contents.managed='-1'" +
				"and if(?filter1<>'',sez_id=?filter1,true) and if(?filter2<>'',cat_id=?filter2,true))" +
				"union " +
				"(SELECT cast(concat('rev',contents.`id`) as char) as id ,contents.titolo,contents.lockid, contents.enabled,contents.managed, (select nome_lingua from " + 
				ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle + "lingue where cultureinfo=contents.lingua) as lingua, " +
				"contents.data_mod,contents.ordine," +
				"'' as tradotto_daNOME,"+
				"sections.titolo as sec_title, categories.titolo as cat_title, sez_id, cat_id, " + 
				"((select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti) + " +
				"(select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"rev_contenuti ) " +
				"where if(?filter1<>'',sez_id=?filter1,true) and if(?filter2<>'',cat_id=?filter2,true) ) as uconteggio, '1' as isrev " +
				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"rev_contenuti as contents " + 
				"left join "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager as sections on contents.sez_id=sections.id " +
				"left join "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager as categories on contents.cat_id=categories.id where contents.managed='-1'" +
				"and if(?filter1<>'',sez_id=?filter1,true) and if(?filter2<>'',cat_id=?filter2,true))" +
				"order by data_mod desc limit ?startl, ?offsetl";
//			HttpContext.Current.Response.Write(query);
			return query;
		}
	
		public string GetAdminSezioniReV() {
//			
			string query = "(SELECT cast(contents.`id` as char) as id,`id` as idf, titolo,contents.lockid,descrizione, autore, ordine, (select nome_lingua from " + 
				ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle + "lingue where cultureinfo=contents.lingua) as lingua, " +
				"data_mod," +
				"(select titolo from "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+
								   "contenuti_manager where id=contents.tradotto_da) as tradotto_daNOME,"+
				"((select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager where managed='-1' and tipo='S') + " +
				"(select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"rev_contenuti_manager where managed='-1' and tipo='S' )) as uconteggio, '0' as isrev  " +
				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager as contents where managed='-1' and tipo='S' " +
				") union ("+
				"SELECT cast(concat('rev',contents.`id`) as char) as id ,`id` as idf, titolo,contents.lockid,descrizione, autore, ordine, (select nome_lingua from " + 
				ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle + "lingue where cultureinfo=contents.lingua) as lingua, " +
				"data_mod," +
				"'' as tradotto_daNOME,"+
				"((select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager where managed='-1' and tipo='S') + " +
				"(select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"rev_contenuti_manager where managed='-1' and tipo='S' )) as uconteggio, '1' as isrev " +
				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"rev_contenuti_manager as contents where managed='-1' and tipo='S')" +
				" order by ordine asc limit ?startl, ?offsetl";
//			HttpContext.Current.Response.Write(query);
			return query;
		}
		
		public string GetRevContenuti(string dove) {
			//HttpContext.Current.Response.Write("select * from " +itareanet.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "contenuti_manager where lingua=?lingua and tipo=?ctype order by titolo ;");
			return "SELECT contents.`id` ,contents.titolo,contents.lockid, contents.enabled,contents.managed,(select nome_lingua from " + 
				ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle + "lingue where cultureinfo=contents.lingua) as lingua, " +
				"contents.data_mod," +
				"sections.titolo as sec_title, categories.titolo as cat_title, sez_id, cat_id," + 
				"(select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"rev_contenuti ) as uconteggio, '1' isrev " +
				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"rev_contenuti as contents " + 
				"left join "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager as sections on contents.sez_id=sections.id " +
				"left join "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager as categories on contents.cat_id=categories.id where contents.managed='-1'" +				
				dove + "order by data_mod desc limit ?startl, ?offsetl";
		}
		public string GetRevSezioni(string dove) {
			//HttpContext.Current.Response.Write("select * from " +itareanet.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "contenuti_manager where lingua=?lingua and tipo=?ctype order by titolo ;");
			return "SELECT `id`,`id` as idf, titolo,contents.lockid, descrizione, autore, ordine, (select nome_lingua from " + 
				ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle + "lingue where cultureinfo=contents.lingua) as lingua, " +
				"data_mod, " +
				"(select count(*) from "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"rev_contenuti_manager where tipo='S') as uconteggio, '1' isrev " +
				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"rev_contenuti_manager as contents " +
				dove + " order by ordine asc limit ?startl, ?offsetl";
		}
		public string GetRevCategorie(string dove) {
			//HttpContext.Current.Response.Write("select * from " +itareanet.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "contenuti_manager where lingua=?lingua and tipo=?ctype order by titolo ;");
			return "SELECT `id`,`id` as idf, titolo,contents.lockid, descrizione, autore, ordine, (select nome_lingua from " + 
				ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle + "lingue where cultureinfo=contents.lingua) as lingua, figliodi as figliodiID," +
				"data_mod,(select titolo from "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager where id = contents.figliodi) as figliodiNOME, " +
				"(select count(*) from "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"rev_contenuti_manager where tipo='C') as uconteggio, '1' isrev " +
				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"rev_contenuti_manager as contents " +
				dove + " order by ordine asc limit ?startl, ?offsetl";
		}
		public string GetRevContenuti_filtered(string dove) {
			//HttpContext.Current.Response.Write("select * from " +itareanet.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "contenuti_manager where lingua=?lingua and tipo=?ctype order by titolo ;");
			return "SELECT contents.`id` ,contents.titolo,contents.lockid, contents.enabled,contents.managed,(select nome_lingua from " + 
				ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle + "lingue where cultureinfo=contents.lingua) as lingua, sez_id, cat_id," +
				"contents.data_mod," +
				"sections.titolo as sec_title, categories.titolo as cat_title," + 
				"(select count(*) from  "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"rev_contenuti " +
				"where if(?filter1<>'',sez_id=?filter1,true) and if(?filter2<>'',cat_id=?filter2,true) "+ dove + ") as uconteggio, '1' isrev " +
				"FROM "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"rev_contenuti as contents " +
				"left join "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager as sections on contents.sez_id=sections.id " +
				"left join "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti_manager as categories on contents.cat_id=categories.id " +
				"where if(?filter1<>'',sez_id=?filter1,true) and if(?filter2<>'',cat_id=?filter2,true) " + dove +
				"order by data_mod desc limit ?startl, ?offsetl";
		}
		public string setAdminContenutiAbilita(string id) {
			//HttpContext.Current.Response.Write("select * from " +itareanet.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+ "contenuti_manager where lingua=?lingua and tipo=?ctype order by titolo ;");
			return "update "+ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle+"contenuti " +
				"set enabled = if(enabled='1','0','1') " +				
				"where id = " +id +" limit 1;";
		}		
		/*id, titolo, atitolo, tag, sez_id, cat_id, testo_breve, testo_html,
		 *  iscommenti, show_autore, show_data, show_titolo, unique_link,
		 *  data_ins, data_mod, ordine, enabled, autore, lingua_ref, template_id, attrib_mostra, attrib_param*/
	
	
		//Per il Controllo Controls_MainButton;
		public string UpdataModuloConfig() {
//			HttpContext.Current.Response.Write(string.Format("UPDATE {0}moduli set data_mod=Now(),titolo=?mnome,descrizione=?mdesc,visible_home=?showmode, blocco_visivo=?mbv,languages=?mlang, parametri=?mparam, addons = ?maddons " +
//			                                                 "where id=?mid limit 1;",ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle));
			return string.Format("UPDATE {0}moduli set data_mod=Now(),titolo=?mnome,descrizione=?mdesc,visible_home=?showmode, blocco_visivo=?mbv," +
			                     "languages=?mlang, parametri=?mparam, addons = ?maddons, connected=?related " +
			                     "where id=?mid limit 1;",ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle);
		}
		public string InsertModuloConfig() {
			return string.Format("INSERT into {0}moduli set data_mod=Now(), data_ins=Now(), titolo=?mnome,descrizione=?mdesc, visible_home=?showmode, languages=?mlang, blocco_visivo=?mbv, parametri=?mparam, addons = ?maddons, connected = ?related,  " +
			                     "id_componente=?mid ;",
			                     ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle);
		}
		
	}
	
	
}
